package com.itchen.hospital.controller;

import com.github.pagehelper.PageInfo;
import com.itchen.hospital.common.Result;
import com.itchen.hospital.pojo.Scheduling;
import com.itchen.hospital.pojo.Params;
import com.itchen.hospital.service.SchedulingService;
import com.itchen.hospital.service.SchedulingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Scheduling")
@Tag(name = "医生排班接口")
@CrossOrigin
@RequiredArgsConstructor
public class SchedulingController {

    private  final SchedulingService schedulingService;

    @GetMapping("/getAll")
    @Operation(summary = "查询所有")
    public Result findByAll() {
        List<Scheduling> list = schedulingService.getAll();
        return Result.success(list);
    }

    @GetMapping("/findBySearch")
    @Operation(summary = "条件查询")
    public Result findBySearch(Params params) {
        PageInfo<Scheduling> list = schedulingService.search(params);
        return Result.success(list);
    }

    @PostMapping("/add")
    @Operation(summary = "添加科室信息")
    public Result add(@RequestBody Scheduling scheduling) {
        schedulingService.add(scheduling);
        return Result.success();
    }

    //根据account回显
    @GetMapping("/findById")
    @Operation(summary = "根据id回显")
    public Result findBySchedulingInfo(String id) {
        Scheduling scheduling = schedulingService.findById(id);
        return Result.success(scheduling);
    }

    @PostMapping("/update")
    @Operation(summary = "修改医生")
    public Result update(@RequestBody Scheduling scheduling) {
        schedulingService.update(scheduling);
        return Result.success();
    }

    @GetMapping("/delete")
    @Operation(summary = "删除科室")
    public Result delete(String id) {
        schedulingService.delete(id);
        return Result.success();
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "批量删除")
    public Result batchDelete(@RequestBody List<Scheduling> schedulings) {
        schedulingService.batchDelete(schedulings);
        return Result.success();
    }

}
